﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Entity;
using GSLMS.Core;

namespace GSLMS.WebAPP.Areas.RiskAudit.Controllers.AuditCon.AuditConArr
{
    public class AuditConArrController : AdminBaseController
    {
        protected override string navTabId
        {
            get { return "RiskAudit_AuditCon_AuditConArr"; }
        }

        [HttpGet]
        public ActionResult Index()
        {
            var searchParam = new TB_ADU_CONARR();
            searchParam.STATUS = 1;

            var model = serviceAduConArr.GetList(searchParam);
            ViewData["RowCount"] = searchParam.RowCount;
           
            ViewData["SearchParma"] = searchParam;
            InitSelect();
            return View(model);
        }

        [HttpPost]
        public ActionResult Index(FormCollection form)
        {
            var searchParam = base.SearchPara<TB_ADU_CONARR>(form, new TB_ADU_CONARR());
            var model = serviceAduConArr.GetList(searchParam);
            ViewData["RowCount"] = searchParam.RowCount;
            InitSelect();
            return View(model);
        }

        protected void InitSelect()
        {
            ViewData["systemID"] = EnumHelper.ToSelectList<GSLMS.Entity.Enum.ApplyEnum.RegSystemID>();
        }

        #region 审议安排

        public ActionResult Create(long id)
        {
            var model = new TB_ADU_CONARR();

            model = serviceAduConArr.GetByID(id);
            if (model.STATUS != 1)
            {
                model.ARRBY = CurentUser.UserName;
                model.ARRBYID = CurentUser.CurrentUserInfo.ID;
                model.CREATEDATE = DateTime.Now;
                model.ARRDATE = DateTime.Now;
            }

            return View(model);
        }

        //
        // POST: /DianDang/Assign/Create

        [HttpPost]
        public string Create(FormCollection collection)
        {
            string result = string.Empty;
            GSLMS.Entity.TB_ADU_CONARR model = new TB_ADU_CONARR();
            TryUpdateModel(model, collection);
            model.STATUS = Helper.ToInt(Request.Form["hidActiondo"].Trim());
            model.ARRMEMBERS = Request.Form["arrMembersGroup.empName"].Trim();
            model.ARRMEMBERSID = Request.Form["arrMembersGroup.empID"].Trim();
            model.HEADMAN = Request.Form["HEADMAN.empName"].Trim();
            model.HEADMANID = Helper.ToLong(Request.Form["HEADMAN.empID"].Trim());
            try
            {
                
                bool isSumbit = false;
                isSumbit = serviceAduConArr.Update(model);
                
                if (isSumbit)
                { result = AjaxResultSucess; }
                else
                { result = AjaxResultFail; }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }

            return "{" + result + "}";
        }
        
        #endregion

        #region 复议安排

       
        [HttpPost]
        public string ReConArrCreate(FormCollection collection)
        {
            string result = string.Empty;
            //GSLMS.Entity.TB_ADU_ASSIGN model = new TB_ADU_ASSIGN();

            //try
            //{
            //    string flowUser = collection["FlowUser"];


            //    model.ID = 0;
            //    model.PROID = Request["id"] == null ? 0 : GSLMS.Core.Helper.ToLong(Request["id"]);
            //    model.ASSIGNBY = CurentUser.UserName;
            //    model.ASSIGNTIME = DateTime.Now;
            //    model.FLOWUSER = flowUser;


            //    bool isSumbit = false;
            //    isSumbit = serviceAduAssign.Add(model);
            //    if (isSumbit)
            //    { result = AjaxResultSucess; }
            //    else
            //    { result = AjaxResultFail; }
            //}
            //catch (Exception ex)
            //{
            //    base.ExceptionHand(ex);
            //    result = AjaxResultFail;
            //}

            return "{" + result + "}";
        }

        #endregion

        #region 退回

        [HttpPost]
        public string BackTo(long id)
        {
            string result = string.Empty;
            string actionBy = CurentUser.UserName;
            string backReason="";
            int backtoFlow=0;

            try
            {
                int num = serviceAduConArr.BackTo(id, actionBy, backReason, backtoFlow);
                if (num==1)
                { result =   string.Format(HelperCommon.AJAXFORMAT, 200, ResourceManager.BackSucces, navTabId, "", "forward"); }
                else if(num==-1)
                {
                    result = string.Format(HelperCommon.AJAXFORMAT, 200, ResourceManager.BackUncan, "", "", "");
                }
                else
                { result = string.Format(HelperCommon.AJAXFORMAT, 200, ResourceManager.BackFail, "", "", ""); }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }


            return "{" + result + "}";
        }

        #endregion

    }
}
